package org.rayken.trix.commons.game.runTypes;

import java.util.List;

import org.rayken.trix.commons.card.Card;
import org.rayken.trix.commons.card.Suit;
import org.rayken.trix.commons.game.Game;
import org.rayken.trix.commons.game.Play;
import org.rayken.trix.commons.game.Player;
import org.rayken.trix.commons.game.Run;
import org.rayken.trix.commons.game.RunType;
import org.rayken.trix.commons.game.Trick;

public class PoisonousDiamondsRun  extends Run {
	
	protected PoisonousDiamondsRun(Game game, Player caller, boolean forced) {
		super(game, caller, forced);

	}

	private int diamondsPlayed = 0;
	static final int PENALTY_SCORE = 10;
	
	@Override
	public boolean isFinished() {
		Trick lastTurn = getLastPlayedTrick();
		if (lastTurn.isComplete() && diamondsPlayed == 8)
			return true;
		return false;
	}

	@Override
	public RunType getType() {
		return RunType.POISONOUS_DIAMONDS;
	}

	@Override
	public void cardPlayed(Player player, Trick turn, Card cardPlayed) {
		if (turn.isComplete()){
			Player victim = turn.getWiningPlay().getPlayer();
			int scoreToAdd = 0;
			for(Play p : turn.getPlays()){
				if (p.getCard().getSuit() == Suit.DIAMONDS){
					diamondsPlayed++;
					scoreToAdd += PENALTY_SCORE;
				}
			}
			if (forced)
				scoreToAdd *= 2;
			if (victim.equals(caller))
				scoreToAdd *= 2;
			addScore(victim, scoreToAdd);
		}
		deals.get(player).remove(cardPlayed);
	}

	@Override
	public List<Card> getAvailablePlayableCard(Player player, Trick turn) {
		return super.getAvailablePlayableCardDefault(player, turn);
	}

}












